//默认导出，一个文件只能默认导出一次
// export default render
//const num = 100;
// export default Number;//ERROR
//命名导出
export const render =(element,container)=>{
    const{type,props}=element;
    //创建元素
    const ele = document.createElement(type);
    //遍历属性
    // console.log(Object.keys(props))
    Object.keys(props).forEach(attr=>{
        if(attr == 'children'){
            const child = props['children'];

            if(typeof child == 'string'){
                ele.innerText = child;
            }else if(child instanceof Array){
                child.forEach(elem =>{
                    if(typeof elem == 'string'){
                        // ele.innerHTML += elem;
                        const textNode = document.createTextNode(elem);
                        ele.appendChild(textNode);
                    }else{
                        render(elem,ele)
                        
                    }
                })
            }else{
                render(child,ele)
            }
        }else{
            ele[attr] = props[attr]
            //ele.setAattribute(attr,props[attr])
        }
    })
    container.appendChild(ele)
}